package com.wc.alorithm_luogu._思维.DlgtTemplate;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/11/10 16:53
 * @description
 * https://www.luogu.com.cn/problem/T454254?contestId=127930
 * TODO 有点难度
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 3010;
    static int[] a = new int[N], b = new int[N];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 0; i < n; i++) a[i] = sc.nextInt();
        int x = 0;
        for (int i = 0; i < n; i++) {
            b[i] = sc.nextInt();
            x = Math.max(x, b[i]);
        }
        int[] f = new int[n];
        if (n <= 20){
            long res = 0, state = 0;
            for (int i = 0; i < 1 << n; i++){
//                i = 644;
                Arrays.fill(f, 0);
                int cnt = 0, use = 0;
                for(int j = 0; j < n; j++){
                    if ((i >> j & 1) == 1) {
                        if (b[j] >= cnt - use) use = cnt;
                        else use += b[j];
                        f[cnt++] = a[j];
                    }
                }
                long tmp = 0;
                for (int j = use; j < cnt; j++) tmp += f[j];
                if (tmp > res) {
                    res = tmp;
                    state = i;
//                    out.println(state + " " + res);
                }
            }
            int cnt = 0;
            for (int i = 0; i < n; i++) cnt += (state >> i & 1);
            out.println(cnt);
            for (int i = 0; i < n; i++) {
                if ((state >> i & 1) == 1){
                    out.print(i + 1 + " ");
                }
            }
            out.println();
            out.println(res);
        } else if (x == 0){
            long res = 0;
            int cnt = 0;
            for(int i = 0; i <= n; i++){
                if (a[i] > 0) {
                    res += a[i];
                    f[cnt++] = i + 1;
                }
            }
            out.println(cnt);
            for (int i = 0; i < cnt; i++) out.print(f[i] + " ");
            out.println();
            out.println(res);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}